<?php
/**
 * 
 * @authors Liujinbi (857053791@QQ.com)
 * @date    2017-08-14 11:19:38
 * @version $Id$
 */

namespace app\mall\controller;

use think\Db;
use think\Request;
use think\Config;
use think\Controller;

class Goodstag extends Controller {

	/**
	 * 根据商品所属分类查出标签
	 * @return [type] [description]
	 */
	function index(){
		$param = Request()->param();
		!$param['cate_id'] && $this->error('参数错误');
		$cate_id = $param['cate_id'];

		$cat = CAT('goods_category',array('cate_id','cate_pid','cate_name','fullname'),'cate_status=1');
		$cate_ids = implode(',',array_column($cat->getChildren($cate_id),'cate_id'));

		$list  = Db::field("GROUP_CONCAT(keywords Separator ' ') as keywords")
		->table('sdzx_goods')->alias('g')
		->join('sdzx_goods_specval sval','g.goods_id=sval.goods_id')
		->where("g.category_id in ({$cate_ids})")
		->find();
		$keywords = array_unique(array_filter(explode(',',preg_replace("/\s+/", ',', trim($list['keywords'])))));
		$return_arr = [];
		foreach ($keywords as $k => $v) {
			$return_arr[] = ['label_id'=>$k,'label_name'=>$v];
		}
		$this->success('success','',$return_arr);
	}

}